package com.syg.servlet01;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 设置refresh响应头，让浏览器定时刷新
 */
@WebServlet("/refresh")
public class _04_Browser_refresh extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置refresh响应头,让浏览器每隔3秒定时刷新
        //resp.setHeader("refresh","3");

        /**
         * -----------------------代码功能分割线----------------------
         */
        //设置refresh响应头，让浏览器3秒后跳转到http://www.baidu.com
        resp.setHeader("refresh","3;url='https://www.baidu.com'");
        //控制输出的编码格式,防止乱码
        resp.setContentType("text/html;charset=utf-8");
        //获取输出流
        resp.getWriter().write("我是字符输出流");
    }
}
